<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>课程详情 - 教学管理系统</title>
    <style>
        body {
            font-family: 'Microsoft YaHei', sans-serif;
            background-color: #f5f5f5;
            margin: 0;
            padding: 0;
        }

        .container {
            display: flex;
            min-height: 100vh;
        }

        .sidebar {
            width: 250px;
            background-color: #2c3e50;
            color: white;
            padding-top: 20px;
        }

        .sidebar-header {
            padding: 0 20px 20px;
            border-bottom: 1px solid #3c5166;
        }

        .sidebar-header h2 {
            margin: 0;
            font-size: 20px;
        }

        .user-info {
            margin-top: 10px;
            font-size: 14px;
            opacity: 0.8;
        }

        .menu {
            list-style: none;
            padding: 0;
            margin: 20px 0;
        }

        .menu li {
            padding: 12px 20px;
            cursor: pointer;
            transition: background-color 0.3s;
        }

        .menu li:hover {
            background-color: #3c5166;
        }

        .menu li.active {
            background-color: #3498db;
        }

        .menu a {
            color: white;
            text-decoration: none;
            display: block;
        }

        .content {
            flex: 1;
            padding: 20px;
        }

        .content-header {
            margin-bottom: 30px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .content-header h1 {
            margin: 0;
            color: #333;
            font-size: 24px;
        }

        .breadcrumb {
            display: flex;
            list-style: none;
            padding: 0;
            margin: 0 0 10px 0;
        }

        .breadcrumb li {
            font-size: 14px;
            color: #777;
        }

        .breadcrumb li:not(:last-child)::after {
            content: '>';
            margin: 0 8px;
        }

        .breadcrumb a {
            color: #3498db;
            text-decoration: none;
        }

        .breadcrumb a:hover {
            text-decoration: underline;
        }

        .course-header {
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            padding: 20px;
            margin-bottom: 20px;
        }

        .course-title {
            font-size: 22px;
            margin: 0 0 10px 0;
            color: #333;
        }

        .course-id {
            font-size: 14px;
            color: #777;
            margin-bottom: 20px;
        }

        .course-meta {
            display: flex;
            flex-wrap: wrap;
            gap: 20px;
            margin-top: 20px;
        }

        .meta-item {
            flex: 1;
            min-width: 150px;
        }

        .meta-label {
            font-size: 12px;
            color: #777;
            margin-bottom: 5px;
        }

        .meta-value {
            font-size: 16px;
            color: #333;
            font-weight: 500;
        }

        .section {
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            padding: 20px;
            margin-bottom: 20px;
        }

        .section-title {
            font-size: 18px;
            color: #333;
            margin: 0 0 20px 0;
            padding-bottom: 10px;
            border-bottom: 1px solid #eee;
        }

        .description {
            color: #555;
            line-height: 1.6;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 10px;
        }

        table th,
        table td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid #eee;
        }

        table th {
            background-color: #f8f9fa;
            color: #333;
            font-weight: 600;
        }

        table tr:hover {
            background-color: #f5f5f5;
        }

        .btn {
            display: inline-block;
            padding: 8px 16px;
            background-color: #3498db;
            color: white;
            border-radius: 4px;
            text-decoration: none;
            font-size: 14px;
            border: none;
            cursor: pointer;
        }

        .btn:hover {
            background-color: #2980b9;
        }

        .btn-group {
            display: flex;
            gap: 10px;
        }

        .btn-green {
            background-color: #27ae60;
        }

        .btn-green:hover {
            background-color: #219955;
        }

        .btn-orange {
            background-color: #f39c12;
        }

        .btn-orange:hover {
            background-color: #e67e22;
        }

        .logout {
            margin-top: auto;
            padding: 20px;
        }

        .logout a {
            color: #e74c3c;
            text-decoration: none;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="sidebar">
            <div class="sidebar-header">
                <h2>教学管理系统</h2>
                <div class="user-info" th:if="${session.user}">
                    <span th:text="${session.user.username}">teacher1</span> - 教师
                </div>
            </div>
            <ul class="menu">
                <li><a href="/teacher/dashboard">我的概览</a></li>
                <li class="active"><a href="/teacher/courses">我的课程</a></li>
                <li><a href="/teacher/students">我的学生</a></li>
                <li><a href="/teacher/grades">成绩管理</a></li>
                <li><a href="/teacher/profile">个人信息</a></li>
            </ul>
            <div class="logout">
                <a href="/logout">退出登录</a>
            </div>
        </div>

        <div class="content">
            <ul class="breadcrumb">
                <li><a href="/teacher/dashboard">我的概览</a></li>
                <li><a href="/teacher/courses">我的课程</a></li>
                <li th:text="${course.name}">课程详情</li>
            </ul>

            <div class="content-header">
                <h1>课程详情</h1>
                <div class="btn-group">
                    <a th:href="@{'/teacher/course/' + ${course.courseId} + '/edit'}" class="btn btn-green">编辑课程</a>
                    <button onclick="deleteCourse()" class="btn btn-orange">删除课程</button>
                </div>
            </div>

            <!-- 添加更新成功消息 -->
            <div class="alert" id="successAlert"
                style="display: none; background-color: #d4edda; color: #155724; border: 1px solid #c3e6cb; border-radius: 4px; padding: 15px; margin-bottom: 20px;">
                课程信息已成功更新！
            </div>

            <!-- 添加删除确认模态框 -->
            <div id="deleteModal"
                style="display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.5); z-index: 1000;">
                <div
                    style="background: white; width: 400px; padding: 20px; border-radius: 8px; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);">
                    <h3 style="margin-top: 0;">确认删除</h3>
                    <p>您确定要删除课程 "<span th:text="${course.name}">计算机导论</span>" 吗？此操作不可撤销。</p>
                    <div style="display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px;">
                        <button onclick="closeDeleteModal()"
                            style="padding: 8px 16px; background: #ccc; border: none; border-radius: 4px; cursor: pointer;">取消</button>
                        <form th:action="@{'/teacher/course/' + ${course.courseId} + '/delete'}" method="post">
                            <button type="submit"
                                style="padding: 8px 16px; background: #e74c3c; color: white; border: none; border-radius: 4px; cursor: pointer;">确认删除</button>
                        </form>
                    </div>
                </div>
            </div>

            <div class="course-header">
                <h2 class="course-title" th:text="${course.name}">计算机导论</h2>
                <div class="course-id" th:text="${'课程编号：' + course.courseId}">课程编号：CS101</div>
                <div class="course-meta">
                    <div class="meta-item">
                        <div class="meta-label">学分</div>
                        <div class="meta-value" th:text="${course.credit}">4</div>
                    </div>
                    <div class="meta-item">
                        <div class="meta-label">总学时</div>
                        <div class="meta-value" th:text="${course.totalHours}">64</div>
                    </div>
                    <div class="meta-item">
                        <div class="meta-label">学期</div>
                        <div class="meta-value" th:text="${course.semester}">大一上</div>
                    </div>
                    <div class="meta-item">
                        <div class="meta-label">专业</div>
                        <div class="meta-value" th:text="${course.major}">计算机科学与技术</div>
                    </div>
                    <div class="meta-item">
                        <div class="meta-label">课程类型</div>
                        <div class="meta-value" th:text="${course.courseType}">必修</div>
                    </div>
                    <div class="meta-item">
                        <div class="meta-label">学生数</div>
                        <div class="meta-value" th:text="${course.studentCount}">35</div>
                    </div>
                </div>
            </div>

            <div class="section">
                <h3 class="section-title">课程介绍</h3>
                <div class="description" th:text="${course.description != null ? course.description : '暂无课程介绍信息'}">
                    计算机导论是一门为计算机专业新生开设的基础课程，旨在帮助学生了解计算机的基本概念和原理。
                    课程内容涵盖计算机发展历史、计算机组成原理、操作系统基础、网络基础、数据库基础等多个方面。
                    通过本课程的学习，学生能够对计算机科学有一个全面的认识，为后续专业课程的学习打下坚实基础。
                </div>
            </div>

            <div class="section">
                <h3 class="section-title">上课安排</h3>
                <table>
                    <tr>
                        <th>教室</th>
                        <td th:text="${course.classroom != null ? course.classroom.building : '未分配'}">A101</td>
                    </tr>
                    <tr>
                        <th>上课时间</th>
                        <td
                            th:text="${course.classDay + ' ' + (course.startTime != null ? course.startTime : '') + '-' + (course.endTime != null ? course.endTime : '')}">
                            周一 8:00-9:40</td>
                    </tr>
                    <tr>
                        <th>周次</th>
                        <td th:text="${course.weeks != null ? course.weeks : '全学期'}">1-16周</td>
                    </tr>
                    <tr>
                        <th>地点详情</th>
                        <td th:text="${course.locationDetail != null ? course.locationDetail : ''}">教学楼A栋101室</td>
                    </tr>
                </table>
            </div>

            <div class="section">
                <h3 class="section-title">快捷操作</h3>
                <div class="btn-group">
                    <a th:href="@{'/teacher/course/' + ${course.courseId} + '/materials'}" class="btn">教学资料</a>
                    <a th:href="@{'/teacher/course/' + ${course.courseId} + '/attendance'}" class="btn">考勤管理</a>
                    <a th:href="@{'/teacher/course/' + ${course.courseId} + '/assignments'}" class="btn">作业管理</a>
                    <a th:href="@{'/teacher/course/' + ${course.courseId} + '/exams'}" class="btn">考试管理</a>
                </div>
            </div>

            <div class="section">
                <h3 class="section-title">操作</h3>
                <div class="btn-group">
                    <a th:href="@{'/teacher/course/' + ${course.courseId} + '/edit'}" class="btn">编辑课程</a>
                    <button onclick="deleteCourse()" class="btn" style="background-color: #e74c3c;">删除课程</button>
                </div>
            </div>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function () {
            console.log('课程详情页面加载完成');

            // 检查URL参数，显示成功消息
            if (window.location.search.includes('updated=1')) {
                const successAlert = document.getElementById('successAlert');
                successAlert.style.display = 'block';

                // 3秒后自动隐藏成功消息
                setTimeout(function () {
                    successAlert.style.display = 'none';
                }, 3000);
            }
        });

        // 显示删除确认对话框
        function deleteCourse() {
            document.getElementById('deleteModal').style.display = 'block';
        }

        // 关闭删除确认对话框
        function closeDeleteModal() {
            document.getElementById('deleteModal').style.display = 'none';
        }
    </script>
</body>

</html>